package com.bi.autotest.operations;

import com.auto.base.OperateAppium;
import com.bi.autotest.pages.CScanBPage;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;

/**
 * Created by yidian on 2018/4/23.
 */
public class CScanBOperation extends OperateAppium {

    private CScanBPage cScanBPage;

    public CScanBOperation(AndroidDriver androidDriver) {
        super(androidDriver);
        cScanBPage=new CScanBPage(androidDriver);
    }

    public void longPressQRCodeImg(){
        longPress(cScanBPage.getCommonQRCodeImg());
        sleep(2000);
        AndroidElement ae2=cScanBPage.getChooseQRCode();
        ae2.click();
        sleep(5000);
        //如果含有马上惠的图层则去点击
        if(cScanBPage.getMSHCloseButton()!=null){
            cScanBPage.getMSHCloseButton().click();
        }
        sleep(2000);
    }

    public boolean payZero(){
        cScanBPage.getKeyCode_0().click();
        cScanBPage.getKeyCode_DOT().click();
        cScanBPage.getKeyCode_0().click();
        cScanBPage.getKeyCode_0().click();
        cScanBPage.getConfirmPayButton().click();
        sleep(2000);
        boolean isExistVipCardPay=cScanBPage.isExistVipCardPayButton();
        pressBackKey();
        sleep(2000);
        return  isExistVipCardPay;
    }

    public boolean payCorrectMoneyLeague(){
        cScanBPage.getKeyCode_0().click();
        cScanBPage.getKeyCode_DOT().click();
        cScanBPage.getKeyCode_0().click();
        cScanBPage.getKeyCode_1().click();
        cScanBPage.getConfirmPayButton().click();
        sleep(2000);

        boolean isExistVipCardPay=cScanBPage.isExistElementByName("会员卡付款");
        print("输入0.01元的情况："+isExistVipCardPay);
       // AndroidElement ae_vipfu=cScanBPage.getElementByName("会员卡付款");
        //点击绝对位置
        pressAbsolutePoint(getScreenWidth()-100,getScreenHeight()-30,50);
        sleep(10000);

        boolean isPaySuccess=cScanBPage.isExistPaySuccessText();
        print("输入0.01元  是否支付成功的情况2："+isPaySuccess);
        pressBackKey();
        sleep(4000);
        cScanBPage.getLeftCloseButton().click();
        sleep(4000);
        return  isExistVipCardPay && isPaySuccess;
    }


    public boolean payCorrectMoneyVipMark() {
        cScanBPage.getKeyCode_0().click();
        cScanBPage.getKeyCode_DOT().click();
        cScanBPage.getKeyCode_0().click();
        cScanBPage.getKeyCode_2().click();

        //切换支付方式
        cScanBPage.getPayTypeButton().click();
        sleep(2000);
      //  print(getScreenHeight()+"    "+getScreenWidth());//  1184     720

        //切换卡的类型
        pressAbsolutePoint(100,getScreenHeight()-150,50);
       // cScanBPage.getVipCardPayItem().click();
        input(cScanBPage.getRemarkInputArea(),"中国红");

        cScanBPage.getConfirmPayButton().click();
        sleep(2000);


        //点击会员卡支付
        pressAbsolutePoint(getScreenWidth()-100,getScreenHeight()-30,50);
        sleep(10000);
        boolean isPaySuccess=cScanBPage.isExistPaySuccessText();
        //点击下拉的箭头
        cScanBPage.getDownButton().click();
        sleep(3000);
        boolean isExistRenark=cScanBPage.isExistResultRemarkText();
        print("是否付款成功："+isPaySuccess+"     是否存在备注："+isExistRenark);
     //   swipeToUp(2000);
        //收起箭头
        cScanBPage.getDownButton().click();

        //关闭此页面
        cScanBPage.getLeftCloseButton().click();
        return  isPaySuccess;
    }

    public boolean payCorrectMoneyMarkLeagueWX() {
        cScanBPage.getKeyCode_1().click();
        cScanBPage.getKeyCode_0().click();
        cScanBPage.getKeyCode_0().click();
        cScanBPage.getKeyCode_0().click();
        cScanBPage.getConfirmPayButton().click();
        sleep(2000);

        //点击会员卡支付
        pressAbsolutePoint(getScreenWidth()-100,getScreenHeight()-30,50);
        sleep(10000);

        boolean isSuccess=cScanBPage.isExistPayRightAwayButton();
        //点击两次返回键 返回到扫码的界面
        pressBackKey();
        sleep(2000);
        cScanBPage.getLeftCloseButton().click();
        sleep(2000);
        return isSuccess;
    }

    public boolean payCorrectMoneyMarkVipWX() {
        cScanBPage.getKeyCode_1().click();
        cScanBPage.getKeyCode_0().click();
        cScanBPage.getKeyCode_0().click();
        cScanBPage.getKeyCode_0().click();
        sleep(2000);

        //切换支付方式
        cScanBPage.getPayTypeButton().click();
        sleep(2000);
        pressAbsolutePoint(100,getScreenHeight()-150,50);
       // cScanBPage.getVipCardPayItem().click();
        sleep(2000);

        cScanBPage.getConfirmPayButton().click();
        sleep(3000);
        //点击会员卡支付
        pressAbsolutePoint(getScreenWidth()-100,getScreenHeight()-30,50);
        sleep(10000);

        boolean isSuccess=cScanBPage.isExistPayRightAwayButton();
        //点击两次返回键 返回到扫码的界面
        pressBackKey();
        sleep(2000);
        cScanBPage.getLeftCloseButton().click();
        sleep(2000);
        return isSuccess;

    }

    //设置金额为0.00的情况
    public boolean payZeroSet() {
        cScanBPage.getSetMoneyButton().click();
        sleep(2000);

        pressAbsolutePoint(300,1120,50);
        // cScanBPage.getKeyCode_0().click();
        pressAbsolutePoint(400,1120,50);
       // cScanBPage.getKeyCode_DOT().click();
        pressAbsolutePoint(300,1120,50);
       // cScanBPage.getKeyCode_0().click();
        pressAbsolutePoint(300,1120,50);
       // cScanBPage.getKeyCode_0().click();
        pressAbsolutePoint(700,1120,50);
       // cScanBPage.getSetConfirmButton().click();
        sleep(5000);
        boolean isExistInputMoneyText=cScanBPage.isExistInputMoneyText();
        print(isExistInputMoneyText);
        if(isExistInputMoneyText){
            cScanBPage.getSetEffectConfirmButton().click();
            sleep(1000);
        }
        return isExistInputMoneyText;
    }

    public boolean payCorrectSet() {
        pressAbsolutePoint(680,850,50);
       // cScanBPage.getSetDelButton().click();
        pressAbsolutePoint(50,850,50);
       // cScanBPage.getKeyCode_1().click();
        pressAbsolutePoint(700,1120,50);
        // cScanBPage.getSetConfirmButton().click();
        sleep(5000);
        boolean isExistClearText=cScanBPage.isExistClearText();
        boolean isExistJine=cScanBPage.isExistSmallJineText();

        print("isExistClearText:"+isExistClearText+"      isExistJine:"+isExistJine);

        return  isExistClearText && isExistJine;
    }

    public boolean payCorrectSetVip() {
        cScanBPage.getPayTypeButton().click();
        sleep(2000);
        pressAbsolutePoint(100,getScreenHeight()-150,50);
       // cScanBPage.getVipCardPayItem().click();
        sleep(2000);
        cScanBPage.getSetSubmissionButton().click();
        sleep(2000);
        boolean isExistVipPayButton=cScanBPage.isExistVipCardPayButton();
        cScanBPage.getLeftCloseButton().click();
        sleep(2000);

        cScanBPage.getSetClearButton().click();
        sleep(2000);
        cScanBPage.getElementByName("确定").click();
        sleep(5000);

        return isExistVipPayButton;
    }

    public boolean payCorrectSetLeague() {
        cScanBPage.getSetSubmissionButton().click();
        sleep(5000);
        boolean isExistVipPayButton=cScanBPage.isExistVipCardPayButton();
        print(isExistVipPayButton);
        cScanBPage.getLeftCloseButton().click();
        sleep(2000);
        return isExistVipPayButton;
    }

    //清除之前的0.01设置为1000元
    public void setLargeAmount() {
        boolean isExistSetMoneyText=cScanBPage.isExistSetMoneyText();
        print("清除之前的0.01 是否成功："+isExistSetMoneyText);
        //设置金额为1000元
        cScanBPage.getSetMoneyButton().click();
        sleep(2000);
        pressAbsolutePoint(50,850,50);
        // cScanBPage.getKeyCode_1().click();
        pressAbsolutePoint(300,1120,50);
        // cScanBPage.getKeyCode_0().click();
        pressAbsolutePoint(300,1120,50);
        // cScanBPage.getKeyCode_0().click();
        pressAbsolutePoint(300,1120,50);
        // cScanBPage.getKeyCode_0().click();
        pressAbsolutePoint(700,1120,50);
        // cScanBPage.getSetConfirmButton().click();
        sleep(5000);
        boolean isExistClearText=cScanBPage.isExistClearText();
        print("设置为1000 是否成功："+isExistClearText);

    }

    public boolean payCorrectSetVipWX() {
        cScanBPage.getPayTypeButton().click();
        sleep(2000);

        pressAbsolutePoint(100,getScreenHeight()-150,50);
       // cScanBPage.getVipCardPayItem().click();
        sleep(2000);
        cScanBPage.getSetSubmissionButton().click();
        sleep(2000);
        //点击会员卡支付
        pressAbsolutePoint(getScreenWidth()-100,getScreenHeight()-30,50);
        sleep(10000);

        boolean isExistPayRightAwayButton=cScanBPage.isExistPayRightAwayButton();
        //点击两次返回键 返回到扫码的界面
        pressBackKey();
        sleep(2000);
        cScanBPage.getLeftCloseButton().click();
        sleep(2000);
        //清除设置的金额
        cScanBPage.getSetClearButton().click();
        sleep(2000);
        cScanBPage.getElementByName("确定").click();
        sleep(5000);
        return isExistPayRightAwayButton;
    }

    public boolean payCorrectSetLeagueWX() {
        cScanBPage.getSetSubmissionButton().click();
        sleep(2000);
        //点击会员卡支付
        pressAbsolutePoint(getScreenWidth()-100,getScreenHeight()-30,50);
        sleep(10000);

        boolean isExistPayRightAwayButton=cScanBPage.isExistPayRightAwayButton();
        //点击两次返回键 返回到扫码的界面
        pressBackKey();
        sleep(2000);
        cScanBPage.getLeftCloseButton().click();
        sleep(2000);
        return isExistPayRightAwayButton;
    }

    public boolean payCorrectSetAddGoods() {
        boolean isExistSetMoneyText=cScanBPage.isExistSetMoneyText();
        print("清除之前的1000 是否成功："+isExistSetMoneyText);

        cScanBPage.getSetMoneyButton().click();
        sleep(2000);
        pressAbsolutePoint(524,535,50);
       // cScanBPage.getAddGoodsButton().click();
        sleep(5000);
        //选取两个测试商品
        pressAbsolutePoint(650,450,50);
        pressAbsolutePoint(650,450,50);
        sleep(2000);
      //  cScanBPage.getAddXWZButton().click();
       // cScanBPage.getAddXWZButton().click();
        cScanBPage.getConfirmAddButton().click();
        sleep(5000);
        longPressQRCodeImg();
        sleep(2000);
        cScanBPage.getSetSubmissionButton().click();
        sleep(2000);

        //点击联盟卡卡支付
        pressAbsolutePoint(getScreenWidth()-100,getScreenHeight()-30,50);
        sleep(10000);

        boolean isPaySuccess=cScanBPage.isExistPaySuccessText();
        cScanBPage.getLeftCloseButton().click();
        sleep(2000);
        //最后清除之前设置的商品
        cScanBPage.getSetClearButton().click();
        sleep(2000);
        cScanBPage.getElementByName("确定").click();
        sleep(5000);
        boolean isExistSetMoneyText2=cScanBPage.isExistSetMoneyText();
        print("清除之前添加的商品 是否成功："+isExistSetMoneyText2);

        return isExistSetMoneyText && isPaySuccess;
    }

    public boolean setMoneyManyTimes() {
        sleep(2000);
        cScanBPage.getSetMoneyButton().click();
        sleep(2000);
        pressAbsolutePoint(300,1120,50);
        // cScanBPage.getKeyCode_0().click();
        pressAbsolutePoint(400,1120,50);
        // cScanBPage.getKeyCode_DOT().click();
        pressAbsolutePoint(50,850,50);
        // cScanBPage.getKeyCode_1().click();
        pressAbsolutePoint(50,850,50);
        // cScanBPage.getKeyCode_1().click();
        pressAbsolutePoint(700,1120,50);
        // cScanBPage.getSetConfirmButton().click();
        sleep(5000);
        boolean isExistClearText=cScanBPage.isExistClearText();
        print("设置为0.11 是否成功："+isExistClearText);
        cScanBPage.getSetClearButton().click();
        sleep(2000);
        cScanBPage.getElementByName("确定").click();
        sleep(5000);
        boolean isExistSetMoneyText=cScanBPage.isExistSetMoneyText();
        print("清除之前的0.11 是否成功："+isExistSetMoneyText);
        return isExistClearText && isExistSetMoneyText;
    }

    public boolean setAddGoodsManyTimes() {
        cScanBPage.getSetMoneyButton().click();
        sleep(2000);

        pressAbsolutePoint(524,535,50);
        // cScanBPage.getAddGoodsButton().click();
        sleep(5000);
        //选取两个测试商品
        pressAbsolutePoint(650,450,50);
        pressAbsolutePoint(650,450,50);
        sleep(2000);
       // cScanBPage.getAddXWZButton().click();
       // cScanBPage.getAddXWZButton().click();
        cScanBPage.getConfirmAddButton().click();
        sleep(5000);
        boolean isExistClearText=cScanBPage.isExistClearText();
        print("添加商品 是否成功："+isExistClearText);
        cScanBPage.getSetClearButton().click();
        sleep(2000);
        cScanBPage.getElementByName("确定").click();
        sleep(5000);
        boolean isExistSetMoneyText=cScanBPage.isExistSetMoneyText();
        print("清除商品 是否成功："+isExistSetMoneyText);
        return isExistClearText && isExistSetMoneyText;

    }

    public boolean changeStoreFanLiPay() {
        //从故宫店切换到超市店
        cScanBPage.getStoreButton().click();
        sleep(5000);
        cScanBPage.getCSButton().click();
        sleep(5000);
        //测试会员卡余额不足 用返利支付的情况
        longPressQRCodeImg();

        //切换为会员卡
        cScanBPage.getPayTypeButton().click();
        sleep(2000);
        pressAbsolutePoint(100,getScreenHeight()-150,50);
      //  cScanBPage.getVipCardPayItem().click();
        sleep(2000);

        cScanBPage.getKeyCode_2().click();
        cScanBPage.getKeyCode_0().click();
        cScanBPage.getKeyCode_DOT().click();
        cScanBPage.getKeyCode_0().click();
        cScanBPage.getKeyCode_0().click();
        cScanBPage.getSetConfirmButton().click();
        sleep(2000);
        //是否存在消费立减的文字
        boolean isExistLiJian=cScanBPage.isExistLiJianText();
        boolean isExistZheKou=cScanBPage.isExistZheKouText();

        //点击会员卡支付
        pressAbsolutePoint(getScreenWidth()-100,getScreenHeight()-30,50);
        sleep(10000);

        cScanBPage.getLeftCloseButton().click();
        sleep(2000);
        boolean isExistSetMoneyText=cScanBPage.isExistSetMoneyText();
        //从超市店切换到故宫店
        cScanBPage.getStoreButton().click();
        sleep(5000);
        cScanBPage.getGGButton().click();
        sleep(5000);

        return isExistZheKou && isExistLiJian && isExistSetMoneyText;
    }

    public boolean changeFlavor() {
        //从故宫店切换到qwer店
        cScanBPage.getStoreButton().click();
        sleep(5000);
        cScanBPage.getQWERButton().click();
        sleep(5000);
        boolean isExistUnOpen=cScanBPage.isExistUnOpenText();
        //从qwer店切换回故宫店
        cScanBPage.getQWERButton().click();
        sleep(3000);
        cScanBPage.getGGButton().click();
        sleep(5000);

        return isExistUnOpen;
    }

}
